/*
 * @Descripttion: 
 * @TapdLink: https://XXX
 * @DesignsLink: https://XXX
 * @RelatedPersons: XXX[市场]、XXX[产品]、XXX[前端]、XXX[后端]、XXX[设计]
 * @version: 1.0.0
 * @Author: Shentong
 * @Date: 2021-06-21 17:32:12
 */
import Taro from '@tarojs/taro'
import { LOGIN, LOGOUT } from '@/src/constants'

const INITIAL_STATE = {
  token: Taro.getStorageSync('token') || '',
  userInfo: Taro.getStorageSync('userInfo') || {
    realName: '', // 姓名
  },
}

export default function user (state = INITIAL_STATE, action) {
  switch(action.type) {
    case LOGIN:
      const { token, userInfo } = action.payload
      return {
        ...state,
        token,
        userInfo,
      }
    case LOGOUT:
      return {
        ...state,
        token: '',
        userInfo: {}
      }
    default:
      return state
  }
}
